package com.chendx.store.search.controller;

import com.chendx.model.common.dtos.ResponseResult;
import com.chendx.model.search.dto.SearchDto;
import com.chendx.store.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by chendx on 2022/4/19.
 */
@RestController
@RequestMapping("/api/search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @GetMapping
    public ResponseResult search(@RequestParam(required = false) Map<String,String> searchMap){
        String pageNum = searchMap.get("pageNum");
        if (pageNum == null){
            searchMap.put("pageNum","1");
        }
        ResponseResult responseResult = searchService.search(searchMap);
        return responseResult ;
    }

    @PostMapping("/update")
    public ResponseResult update(@RequestBody SearchDto dto){

        return  searchService.update(dto);
    }
}
